package kr.hkit.android_bookmgr.activity;

import kr.hkit.android_bookmgr.R;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

@SuppressLint("SetJavaScriptEnabled")
public class BookBoardWebViewActivity extends Activity {

	private WebView mWeb;
	private int whichone ;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		Log.d("BOARD", "WEBVIEW - onCreate");
		
		setContentView(R.layout.bookboard_webview_activity);
		
		//intent 받기 - 인서트
		Intent intent = getIntent();
		String board_writer = intent.getStringExtra("board_writer");
		String board_comment = intent.getStringExtra("board_comment");
		String board_writedate = intent.getStringExtra("board_writedate");
		
		//삭제용
		whichone = intent.getIntExtra("whichone", -1);
		String board_id_del = intent.getStringExtra("board_id_del");
		
		//수정용
		String board_id_update = intent.getStringExtra("board_id_update");
		String board_writer_update = intent.getStringExtra("board_writer_update");
		String board_comment_update = intent.getStringExtra("board_comment_update");
		String board_writedate_update = intent.getStringExtra("board_writedate_update");
		
		
		mWeb = (WebView) findViewById(R.id.bookboard_webview);
		mWeb.setWebViewClient(new MyWebClient());
		
		WebSettings set = mWeb.getSettings();
		set.setJavaScriptEnabled(true);
		set.setBuiltInZoomControls(true);
		
		if (whichone==0){ //수정
			mWeb.loadUrl("http://121.181.28.212/BookBoard/book/updateProc.jsp?board_id="+board_id_update+"&board_writer="+board_writer_update+"&board_comment="+board_comment_update+"&board_writedate="+board_writedate_update);
		}else if (whichone==1){ //삭제
			mWeb.loadUrl("http://121.181.28.212/BookBoard/book/deleteProc.jsp?board_id="+board_id_del);	
		}else if(whichone==-1){ //삽입
			mWeb.loadUrl("http://121.181.28.212/BookBoard/book/insertProc.jsp?board_writer="+board_writer+"&board_comment="+board_comment+"&board_writedate="+board_writedate);
		}
		
		finish();
		
		
	}
	
	class MyWebClient extends WebViewClient {

		@Override
		public boolean shouldOverrideUrlLoading(WebView view, String url) {
			super.shouldOverrideUrlLoading(view, url);

			view.loadUrl(url);
			return true;
		}
	}

	

}
